//---------------------------------------------------------------------------

#include "vcl_stl.h"
#pragma hdrstop

#include "h_base.h"
#include "h_xml.h"
#include "h_global.h"
using namespace h_base;
using namespace h_xml;

#include "h_stage.h"
#include "t_dummyform.h"

#include "h_g.h"
#include "t_batchjobform.h"
#include "h_portal.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TBatchJobForm *BatchJobForm;
//---------------------------------------------------------------------------
__fastcall TBatchJobForm::TBatchJobForm(TComponent* Owner)
   : TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TBatchJobForm::ButtonOkClick(TObject *Sender)
{
   Close();
}
//---------------------------------------------------------------------------


bool __fastcall TBatchJobForm::Edit(HStageBatch *Stage)
{
   FStage = Stage;
   FStage->GetInfo(Info);
   UTF8String Cap;
   Cap.sprintf(UTF8String(DummyForm->PropertiesOf->Caption).c_str(), Info.Name.c_str());
   Caption = Cap;
   EditName->Text = Info.Name;
   EditCaption->Text = Info.Caption;
   EditHostName->Text = Info.HostName;
   EditBatch->Text = Info.Batch;
   CheckBoxSendDate->Checked = Info.SendDate;
   EditDateVarName->Text = Info.DateVarName;
   SetStringToMemo(MemoDescription, Info.Description);
   SetStringToMemo(MemoExternJobList, Info.ExternJobListStr);
   EditSpecialDate->Text = Info.SpecialDate;
   CheckBoxCondNot->Checked = Info.CondNot;
   EditConditionFile->Text = Info.ConditionFile;
   EditTag->Text = Info.Tag;
   EditAlarmTimeType->Text = HStage::AlarmTimeTypeToString(Info.AlarmTimeType);
   EditAlarmTime->Text = Info.AlarmTime;
   EditStatus->Text = Info.Status;
   EditStartTime->Text = FormatDateTime(Info.StartTime);
   EditEndTime->Text = FormatDateTime(Info.EndTime);
   EditElapse->Text = DiffTime(Info.StartTime, Info.EndTime, Info.IdleTimeSum);
   EditServerId->Text = ( Info.ServerId == 0 ? UTF8String("") : UTF8String(Info.ServerId) );
   EditPid->Text = ( Info.Pid == 0 ? UTF8String("") : UTF8String(Info.Pid) );

   HBatchIcon *Batch = Info.BatchIcon;
   Batch->Lock();
   HOutlineStatus OutlineStatus = Batch->OutlineStatus;
   Batch->Unlock();
   EditBatchStatus->Text = OutlineStatus.StatusStr;
   EditCompletedRatio->Text = OutlineStatus.CompletedRatio;

   ShowModal();
   return true;
}

